﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HPMDesktop.Patient;
using SecurityController;

namespace HPMDesktop
{
    public partial class frmLogin : Form
    {
        public frmLogin()
        {
            InitializeComponent();
        }

        private void cmdLogin_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length == 0 || textBox2.Text.Length == 0)
            {
                MessageBox.Show("Please provide both Used id and Password", "Authentication");
            }
            else if (IsAuthentication() == false)
            { 
                MessageBox.Show("Authentication Failed.","Authentication Fail"); 
            }
            else
            {
                //do authentication
                //this.Close();

                Main fp = new Main();
                fp.FormClosed += new FormClosedEventHandler(fp_FormClosed);
                fp.Show();
                this.Hide();

            }
        }

        private void fp_FormClosed(object sender, FormClosedEventArgs e)
        {
            this.Close();
        }

        private Boolean IsAuthentication()
        {
            LoginAuthentication la = new LoginAuthentication();
            if (la.DoAuthentication(textBox1.Text, textBox2.Text)){ return true; }
            else { return false; }
            
            
        }

        private void frmLogin_Load(object sender, EventArgs e)
        {
            //this.StartPosition = FormStartPosition.CenterScreen;

            //this.Location.X = DesktopLocation.X / 2;
            //this.Location.Y = DesktopLocation.Y / 2;
            textBox2.Focus();
            textBox1.Text = "Admin";

        }

    }
}
